package labox.innovation.gameserver.skills.l2skills;

import labox.innovation.gameserver.model.L2Object;
import labox.innovation.gameserver.model.L2Skill;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.network.SystemMessageId;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;
import labox.innovation.gameserver.templates.StatsSet;
import labox.innovation.util.Rnd;

/**
 * @author Nemesiss
 * 
 */
public class L2SkillCreateItem extends L2Skill {
	private final int[] _createItemId;
	private final int _createItemCount;
	private final int _randomCount;

	public L2SkillCreateItem(StatsSet set) {
		super(set);
		_createItemId = set.getIntegerArray("create_item_id");
		_createItemCount = set.getInteger("create_item_count", 0);
		_randomCount = set.getInteger("random_count", 1);
	}

	/**
	 * @see labox.innovation.gameserver.model.L2Skill#useSkill(labox.innovation.gameserver.model.actor.L2Character,
	 *      labox.innovation.gameserver.model.L2Object[])
	 */
	@Override
	public void useSkill(L2Character activeChar, L2Object[] targets) {
		if (activeChar.isDead())
			return;
		if (activeChar instanceof FuzePcInstance) {
			if (_createItemId == null || _createItemCount == 0) {
				SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
				activeChar.sendPacket(sm);
				return;
			}

			int count = _createItemCount + Rnd.nextInt(_randomCount);
			int rndid = Rnd.nextInt(_createItemId.length);
			((FuzePcInstance) activeChar).addItem("Skill", _createItemId[rndid], count, activeChar, true);
		}
	}
}
